﻿// JScript File

String.prototype.getRealLength=function(){return this.replace(/[^\x00-\xff]/g,"aa").length;};
String.prototype.trim=function() 
{ 
    return this.replace(new RegExp('　','gm'),' ').replace(/(\s*$)|(^\s*)/g, ''); 
} 


function submitInput( evt)
{	
	evt = (evt) ? evt : (window.event) ? event : null;
	if ( evt.keyCode==13){
		
		return true;
	}
		return false;
	
}
function renderSelect(originalRequest)
{
    var tex = originalRequest.responseText;	       
    if(tex == "")
    {
        $("p_result").innerHTML ="提交有误!";
        return;    
    }
    
    $("txt_Content").value='';
    $("p_result").innerHTML = tex;

}



function loadCancelData(orderType,Id)
	{		
	    
        var outputDataUrl = "../outputData.aspx";
		var parsStr = "?Dtype="+ orderType + "&Id=" + Id  + "&d="  + new Date();
        var sUrl = outputDataUrl + parsStr ;
           
		var oXmlHttp ;
		
		try {
			oXmlHttp  =  new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
			oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			oXmlHttp = false;
		}
		}
			
		if (!oXmlHttp && typeof XMLHttpRequest != 'undefined') 
		{
			oXmlHttp = new XMLHttpRequest();
		}
					
		oXmlHttp.open("GET", sUrl, false);				
		oXmlHttp.onreadystatechange = function()
		{		   
			if (oXmlHttp.readyState == 4) {   
			
			    // alert(oXmlHttp.responseText);
				//if (oXmlHttp.responseText!="")
				//{ 
				//  alert(oXmlHttp.responseText);
				   var wp=window.parent;
                   var cf=wp.document.getElementById("orderList");		
                   cf.innerHTML = oXmlHttp.responseText;
				//}								
			}
		}		
		oXmlHttp.send(null)
	}
	
	
		

var outputDataUrl = "/MyHome/outputData.aspx";

//回调数据
function loadData(Type,Content)
{      
    //  var cityId = (arguments.length>1)?arguments[1]:"";             
    // if(orderType == "order") Id =  buildSortValue(orderType,Id);
    var parsStr = "?Dtype="+ Type + "&Content=" + unescape(Content)  + "&d="  + new Date();
    var myurl = outputDataUrl + parsStr ;
         		    
    var pars = "";	   	  
    var myAjax = new  Ajax.Request(myurl,{method: 'get', parameters: pars, onComplete: renderSelect});
}

//显示个人加的DOC左栏
function showPersonList()
{
   var parsStr = "?Dtype=showpersonlist"+"&d="  + new Date();
    var myurl = outputDataUrl + parsStr ;
         		    
    var pars = "";	   	  
    var myAjax = new  Ajax.Request(myurl,{method: 'get', parameters: pars, onComplete: renderShowPersonList});
}

function renderShowPersonList(originalRequest)
{
    var tex = originalRequest.responseText;	   
        
    if(tex == "")
    {
        $("personalList").innerHTML ="";
        return;    
    }
    else
    {
       $("personalList").innerHTML = tex;
    }  

}

//添加个人加的DOC左栏  begion

function addPersonDoc(mingzi,wangzhi)
{
    var parsStr = "?Dtype=addpersonlist&mingzi="+mingzi+"&wangzhi="+wangzhi+"&d="  + new Date();
    var myurl = outputDataUrl + parsStr ;
         		    
    var pars = "";	   	  
    var myAjax = new  Ajax.Request(myurl,{method: 'get', parameters: pars, onComplete: renderAfterAddShowPersonList});
  
}

function addCheck()
{
 if(document.getElementsByName('personal').length==6)
  {
       document.getElementById("warn_result").style.visibility="visible";          
       document.getElementById("warn_result").innerHTML="最多可自定义设置6项！"; 
       return; 
  }
  else
  {
     document.getElementById("warn_result").style.visibility="hidden";    
  }
  
 if(document.getElementById("menu_text").value==null||document.getElementById("menu_text").value=="")
 {
      document.getElementById("warn_menu_text").style.visibility="visible";          
      document.getElementById("warn_menu_text").innerHTML="请输入名称！"; 
       return; 
 }
 else
 {
  document.getElementById("warn_menu_text").style.visibility="hidden";
 }
 if(document.getElementById("menu_text").value.trim().length>8)
 {
      document.getElementById("warn_menu_text").style.visibility="visible";          
      document.getElementById("warn_menu_text").innerHTML="您输入名字过长！"; 
       return; 
 }
 else
 {
  document.getElementById("warn_menu_text").style.visibility="hidden";
 }
 if(document.getElementById("nav_url").value==null||document.getElementById("nav_url").value=="")
 {
      document.getElementById("warn_nav_url").style.visibility="visible";          
      document.getElementById("warn_nav_url").innerHTML="请输入网址！"; 
      return; 
 }
 else
 {
  document.getElementById("warn_nav_url").style.visibility="hidden";
 }
 
 if(checkurl(document.getElementById("nav_url").value)==false)
 {
   document.getElementById("warn_nav_url").style.visibility="visible";          
      document.getElementById("warn_nav_url").innerHTML="网址有误!"; 
      return; 
 }
 else
 {
  document.getElementById("warn_nav_url").style.visibility="hidden";
 }
 
 addPersonDoc(unescape(document.getElementById("menu_text").value),unescape(document.getElementById("nav_url").value))
 
 
 
}

function renderAfterAddShowPersonList(originalRequest)
{
    var tex = originalRequest.responseText;	   
    
    //alert(tex);
        
    if(tex == "have")
    {
    
         $("warn_result").innerHTML ="添加未成功，请重试！";
         $("menu_text").value = "";
         $("nav_url").value = "";
         $("warn_result").style.visibility="visible"; 
        return;    
    }
    else
    {       
       $("personalList").innerHTML = tex;
       $("menu_text").value = "";
       $("nav_url").value = "";
       $("warn_result").style.visibility="hidden"; 
    }  
}
//添加个人加的DOC左栏  end

//删除个人加的DOC左栏  begin

function deletePersonDoc(cust_menu_id,ifshownow)
{
  var parsStr = "?Dtype=deletepersonlist&cust_menu_id="+cust_menu_id+"&ifshownow="+ifshownow+"&d="  + new Date();
    var myurl = outputDataUrl + parsStr ;
         		    
    var pars = "";	   	  
    var myAjax = new  Ajax.Request(myurl,{method: 'get', parameters: pars, onComplete: renderAfterDeleteShowPersonList});
}

function renderAfterDeleteShowPersonList(originalRequest)
{
  var tex = originalRequest.responseText;	   
        
    if(tex == "false")
    {
         $("warn_result").innerHTML ="删除未成功，请重试！";
         $("menu_text").value = "";
         $("nav_url").value = "";
         $("warn_result").style.visibility="visible"; 
        return;    
    }
    else
    { 
       if(tex.indexOf("-")!=-1)
       {
          //alert(tex);
          
           var StrArry = tex.split("-");
           var k = StrArry[0];
           var v = StrArry[1];           
            //alert(k);
            //alert(v);          
           $("personalList").innerHTML = v;  
           
           parent.NormalBind(k);
           $("menu_text").value = "";
           $("nav_url").value = "";
           $("warn_result").style.visibility="hidden"; 
       }  
       else
       {
           $("personalList").innerHTML = tex;
           //alert(" no show now one");
           $("menu_text").value = "";
           $("nav_url").value = "";
           $("warn_result").style.visibility="hidden"; 
       }   
      
    }  
}

//删除个人加的DOC左栏  end

//全部提交 begin
function  allSubmitData(origial_ids,submit_ids)
{
   var parsStr = "?Dtype=allsubmit&origial_ids="+origial_ids+"&submit_ids="+submit_ids+"&d="  + new Date();
    var myurl = outputDataUrl + parsStr ;
         		    
    var pars = "";	   	  
    var myAjax = new  Ajax.Request(myurl,{method: 'get', parameters: pars, onComplete: renderAfterAllSubmitPersonList});
}

function renderAfterAllSubmitPersonList(originalRequest)
{
  var tex = originalRequest.responseText;	 
        //alert(tex);
  
        
    if(tex == "false")
    {
         $("allsubmit_warn").innerHTML ="提交未成功，请重试！";     
         $("allsubmit_warn").style.visibility="visible"; 
        return;    
    }
    else
    {
      //alert(tex);      
      parent.NormalBind(tex);
      parent.hidden1();
    }
}

function  allSubmitCheck()
{
//var vvv =parent.GetCustid();

//alert(vvv);


    var  kk=$("rememberSelectedID").value;
    
    var aaa="";
    var bbb="";
    var count=0;
    
    for(var i=0;i<document.getElementsByName("public").length;i++)
    {
       if(document.getElementsByName("public")[i].checked)
       {
        aaa+=document.getElementsByName("public")[i].value+",";
        
        count+=1;
       }
       
    }
    
    for(var i=0;i<document.getElementsByName("personal").length;i++)
    {
       if(document.getElementsByName("personal")[i].checked)
       {
        bbb+=document.getElementsByName("personal")[i].value+",";
        count+=1;
       }
       
    }    
    var vv=aaa+"|"+bbb;
    
    if(count>5)
    {
      //alert("常用地址只能设置5个！");
      $("allsubmit_warn").innerHTML ="常用地址只能设置5个！";     
      $("allsubmit_warn").style.visibility="visible"; 
    }
    else
    {
      //alert(kk);
      // alert(vv);
       allSubmitData(kk,vv)
    }    
}


function clearAllChecked()
{
    for(var i=0;i<document.getElementsByName("public").length;i++)
    {
       if(document.getElementsByName("public")[i].checked)
       {
        document.getElementsByName("public")[i].checked=false;
       }
       
    }
    
    for(var i=0;i<document.getElementsByName("personal").length;i++)
    {
       if(document.getElementsByName("personal")[i].checked)
       {
         document.getElementsByName("personal")[i].checked=false;
       }
       
    }    

}

function testUrl()
{
//addCheck();
   var str="http://dangdanH";
   
   //var str="http://dangdang.com/product.aspx?product_id=20644810#ref=www-0-H";
   
   var begin= str.substring(0,7);
   
   alert(begin)
   
   checkurl(str);
   
}

function checkurl(url)
{

     if(url.length<20)
     {
      //alert("false");  
      return false
     }
     else
     {
       var begin= url.substring(0,7);
       
       if(begin!="http://")
       {
         //alert("false");  
         return false
       }
       else
       {
         var reUrl =/^http:\/\/[A-Za-z0-9]+\.dangdang\.com.?/;
           
        if (!url.match(reUrl))  
        { 
          //alert("false");                       
         return false;
        }
        else
        {            
         return true;
        }    
       }
       
     }  
}



//全部提交 end





	
function clickResearch()
{
    if(CheckResearchCont()==false)return;
    var content = ReplaceHTML($("txt_Content").value);
    $("p_result").innerHTML =  "<span class='your_news'><img alt='load' src='/MyHome/images/loading.gif' align='absMiddle'  bold='0'  /> 提交中...</span>";

    loadData("research",content);

}

var shopOutputDataUrl = "/MyHome/outputData.aspx";
//回调数据
function shoploadData(Type,Content)
{   
    var parsStr = "?Dtype="+ Type + "&Content=" + Content  + "&d="  + new Date();
    var myurl = shopOutputDataUrl + parsStr ;
         		    
    var pars = "";	   	  
    var myAjax = new  Ajax.Request(myurl,{method: 'get', parameters: pars, onComplete: renderSelectShop});
}

//演示提示框
function clickShopYse()
{ 
    if($("hid_custid").value=='')return;
    shoploadData("shoppop",$("hid_custid").value);
}

function renderSelectShop( originalRequest)
{
    var tex = originalRequest.responseText;	       
    if(tex == "true")
    {
        window.parent.hideMsgBox();
        hideShoppingNotice(window.parent.document);
    }
}